package com.enjoy.list;

public class LinkedList {

    private Node head;

    private int size;

    /**
     * 插入链表头部
     */
    public void insertHead(char value) {
        Node node = new Node(value);
        //如果原来就有数据呢？
        node.next = head;
        head = node;
    }

    /**
     * 插入链表中间的位置
     */
    public void insertNth(char value, int position) {
        if (position == 0) {
            insertHead(value);
        } else {
            Node cur = head;
            for (int i = 0; i < position; i++) {
                cur = cur.next;//找到了这个位置
            }
            Node newNode = new Node(value);
            newNode.next = cur.next;
            cur.next = newNode;
        }
    }

    /**
     * 删除中间的某个
     * @param pos 位置
     */
    public void deleteNth(int pos) {
        if (pos == 0) {
            deleteHead();
        } else {
            Node cur = head;
            for (int i = 0; i < pos; i++) {
                cur = cur.next;
            }
            cur.next = cur.next.next;
        }
    }

    /**
     * 删除头
     */
    public void deleteHead() {
        head = head.next;
    }

    public static void main(String[] args) {


    }

    static class Node {
        char value;

        Node next;

        public Node(char value) {
            this.value = value;
            this.next = null;
        }


    }
}
